﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace NetDon.OA.Interface
{
    public class ModuleCollection : Collection<Module>
    {
        public ModuleCollection() { }
        public ModuleCollection(IList<Module> modules)
            : base(modules)
        {

        }
        public void Sort()
        {
            ((List<Module>)Items).Sort((x, y) => Comparer<int>.Default.Compare(x.Index, y.Index));
        }
    }

    public class Module : ICloneable
    {
        private FunctionCollection _functions;

        /// <summary>
        /// Gets or sets the module ID.
        /// </summary>
        /// <value>The module ID.</value>
        public string ModuleID { get; set; }
        /// <summary>
        /// Gets or sets the module name.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the image URL.
        /// </summary>
        /// <value>
        /// The image URL.
        /// </value>
        public string ImageUrl { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="Module"/> is visible.
        /// </summary>
        /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
        public Boolean Visible { get; set; }
        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index { get; set; }

        public FunctionCollection Functions
        {
            get
            {
                if (_functions == null)
                {
                    _functions = new FunctionCollection(this, null);
                }
                return _functions;
            }
        }

        #region ICloneable Members

        public object Clone()
        {
            return new Module { ModuleID = ModuleID, Name = Name, ImageUrl = ImageUrl, Index = Index, Visible = Visible };
        }

        #endregion

        public override string ToString()
        {
            return ModuleID;
        }
    }
}